﻿using System;
using System.Speech.Synthesis;
using System.Threading.Tasks;
using Microsoft.Win32;

namespace DGRobot
{
    public class SpeechHelper
    {
        public static SpeechSynthesizer Synth = new SpeechSynthesizer();
        public static Prompt currentPrompt;
        public static void Speak(string text)
        {
            Task.Factory.StartNew(() =>
            {
                StopCurrentSpeak();
                currentPrompt = Synth.SpeakAsync(text);
            },TaskCreationOptions.LongRunning);
        }
        public static void StopCurrentSpeak()
        {
            if (currentPrompt != null)
            {
                Synth.SpeakAsyncCancel(currentPrompt);
                currentPrompt = null;
            }
        }
        public static void Stop()
        {
            Synth.SpeakAsyncCancelAll();

        }

        public static void Dispose()
        {
            Stop();
            Synth.Dispose();
        }
    }
}